package com.zygh.interactiveplatform.module.controller;


import com.alibaba.fastjson.JSONObject;
import com.zygh.interactiveplatform.common.anno.PcLog;
import com.zygh.interactiveplatform.common.constant.SwaggerTagConst;
import com.zygh.interactiveplatform.common.domain.ResponseDTO;
import com.zygh.interactiveplatform.module.entity.TrafficControl;
import com.zygh.interactiveplatform.module.service.TrafficControlService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lee
 * @since 2021-02-03
 */
@RestController
@RequestMapping("/traffic-control")
@Api(tags = {SwaggerTagConst.Admin.MANAGER_TRAFFICCONTROL})
public class TrafficControlController {
    @Resource
    private TrafficControlService trafficControlService;

    @ApiOperation(value = "限行配置新增", notes = "限行配置新增")
    @PostMapping("addTrafficControle")
    @PcLog(logType = "2", module = SwaggerTagConst.Admin.MANAGER_TRAFFICCONTROL, content = "限行配置新增")
    public ResponseDTO addTrafficControle(@RequestBody @Valid TrafficControl trafficControl) {
        return trafficControlService.addTrafficControl(trafficControl);
    }

    @ApiOperation(value = "限行配置修改", notes = "限行配置修改")
    @PostMapping("updateTrafficControl")
    @PcLog(logType = "3", module = SwaggerTagConst.Admin.MANAGER_TRAFFICCONTROL, content = "限行配置修改")
    public ResponseDTO updateTrafficControl(@RequestBody @Valid TrafficControl trafficControl) {
        return trafficControlService.updateTrafficControl(trafficControl);
    }

    @ApiOperation(value = "限行配置删除", notes = "限行配置删除")
    @PostMapping("deleteTrafficControl")
    @PcLog(logType = "4", module = SwaggerTagConst.Admin.MANAGER_TRAFFICCONTROL, content = "限行配置删除")
    public ResponseDTO deleteTrafficControl(@RequestBody String id) {
        String s = JSONObject.parseObject(id).get("id").toString();
        Integer new_id = Integer.parseInt(s);
        return trafficControlService.deleteTrafficControl(new_id);
    }

    @ApiOperation(value = "查询所有限行配置", notes = "查询所有限行配置")
    @GetMapping("findTrafficControlAll")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_TRAFFICCONTROL, content = "查询所有限行配置")
    public ResponseDTO findTrafficControlAll(Integer current, Integer size) {
        return trafficControlService.findTrafficControlAll(current, size);
    }
}
